#include "board.h"
#include <rtdevice.h>
#include <rtthread.h>
#ifdef UC_GATEWAY_HARDWARE
#include "drv_gw_power.h"

void gw_main_power_init(void)
{
    // all power enable
    rt_pin_mode(MAIN_POWER, PIN_MODE_OUTPUT);
    rt_pin_write(MAIN_POWER, PIN_HIGH);
    for (int i = 0; i < 1000000; i++)
        ;
}

void gw_debug_power_init(void)
{
    // debug
    rt_pin_mode(DEBUG_POWER, PIN_MODE_OUTPUT);
    rt_pin_write(DEBUG_POWER, PIN_HIGH);
}

void ap_power_init(void)
{
    // ap power enable
    rt_pin_mode(AP_POWER, PIN_MODE_OUTPUT);
    rt_pin_write(AP_POWER, PIN_HIGH);
    // ap8088 reset
    rt_pin_mode(AP8088_RESET, PIN_MODE_OUTPUT);
    rt_pin_write(AP8088_RESET, PIN_LOW);
    // ap8288 reset
    rt_pin_mode(AP8288_RESET, PIN_MODE_OUTPUT);
    rt_pin_write(AP8288_RESET, PIN_LOW);
}

void ap_power_deinit(void)
{
    rt_pin_write(AP_POWER, PIN_LOW);
}

void ap_power_reset(void)
{
    rt_pin_write(AP8088_RESET, PIN_HIGH);
    rt_thread_mdelay(2000);
    rt_pin_write(AP8088_RESET, PIN_LOW);
}

void sync_assistant_power_init(void)
{
    // sync assistant power enable
    rt_pin_mode(SYNC_ASSISTANT_POWER, PIN_MODE_OUTPUT);
    rt_pin_write(SYNC_ASSISTANT_POWER, PIN_HIGH);
    // sync assistant reset
    rt_pin_mode(SYNC_ASSISTANT_RESET, PIN_MODE_OUTPUT);
    rt_pin_write(SYNC_ASSISTANT_RESET, PIN_LOW);
}

void sync_assistant_power_deinit(void)
{
    rt_pin_write(SYNC_ASSISTANT_POWER, PIN_LOW);
}

void sync_assistant_power_reset(void)
{
    rt_pin_write(SYNC_ASSISTANT_RESET, PIN_HIGH);
    rt_thread_mdelay(300);
    rt_pin_write(SYNC_ASSISTANT_RESET, PIN_LOW);
}
#endif